home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.012.Menus / menus.aii < prev    next >
Encoding:
Text File  |  1990-06-24  |  27.8 KB  |  1,227 lines  |  [TEXT/MPS ]

  1. *******************************************************************************
  2. *
  3. * Menus -- Version 3.0
  4. *
  5. * (C)  Copyright Apple Computer, Inc. 1988-1990
  6. * All rights reserved.
  7. *
  8. * Developer Technical Support Apple II Sample Code
  9. *
  10. * by Jim Mensch
  11. *
  12. * Sample Application that demonstrates the use of many menu manager
  13. * calls. It Shows how to add or remove whole menus or menu items, and how to
  14. * manipulate existing items.
  15. * It also demonstrates how to create a custom menu and handle user 
  16. * interactions with it. The custom menu can be removed from this program and 
  17. * incorporated inside your own applications. The custom menu is a color menu
  18. * that allows the user to select one of 4 colors.
  19. *
  20. *******************************************************************************
  21.     eject
  22.     
  23. **********************************************************************
  24. *                                                                    *
  25. *     This program and its derivatives are licensed only for         *
  26. *     use on Apple computers.                                        *
  27. *                                                                    *
  28. *     Works based on this program must contain and                   *
  29. *     conspicuously display this notice.                             *
  30. *                                                                    *
  31. *     This software is provided for your evaluation and to           *
  32. *     assist you in developing software for the Apple IIGS           *
  33. *     computer.                                                      *
  34. *                                                                    *
  35. *     DISCLAIMER OF WARRANTY                                         *
  36. *                                                                    *
  37. *     THE SOFTWARE IS PROVIDED "AS IS" WITHOUT                       *
  38. *     WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,               *
  39. *     WITH RESPECT TO ITS MERCHANTABILITY OR ITS FITNESS             *
  40. *     FOR ANY PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO             *
  41. *     THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH            *
  42. *     YOU.  SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU (AND            *
  43. *     NOT APPLE OR AN APPLE AUTHORIZED REPRESENTATIVE)               *
  44. *     ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING,             *
  45. *     REPAIR OR CORRECTION.                                          *
  46. *                                                                    *
  47. *     Apple does not warrant that the functions                      *
  48. *     contained in the Software will meet your requirements          *
  49. *     or that the operation of the Software will be                  *
  50. *     uninterrupted or error free or that defects in the             *
  51. *     Software will be corrected.                                    *
  52. *                                                                    *
  53. *     SOME STATES DO NOT ALLOW THE EXCLUSION                         *
  54. *     OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY              *
  55. *     NOT APPLY TO YOU.  THIS WARRANTY GIVES YOU SPECIFIC            *
  56. *     LEGAL RIGHTS AND YOU MAY ALSO HAVE OTHER RIGHTS                *
  57. *     WHICH VARY FROM STATE TO STATE.                                *
  58. *                                                                    *
  59. *                                                                    *
  60. **********************************************************************
  61.  
  62.     case   on
  63.     PRINT  NOHDR,NOGEN    
  64.     STRING AsIS
  65.     PRINT  PUSH,OFF
  66.  
  67.     INCLUDE 'M16.Util'
  68.     INCLUDE 'M16.ProDOS'
  69.     INCLUDE 'M16.QUICKDRAW'
  70.     Include 'M16.QDAux'
  71.     Include 'E16.Quickdraw'
  72.     INCLUDE 'M16.MEMORY'
  73.     Include 'E16.Memory'
  74.     INCLUDE 'M16.EVENT'
  75.     INCLUDE 'E16.Event'
  76.     INCLUDE 'M16.LOCATOR'
  77.     INCLUDE 'M16.MISCTOOL'
  78.     INCLUDE 'M16.TextTOOL'
  79.     INCLUDE 'E16.Menu'
  80.     INCLUDE 'M16.Menu'
  81.     INCLUDE 'M16.Control'
  82.     INCLUDE 'M16.Window'
  83.     INCLUDE 'E16.Window'
  84.     INCLUDE 'M16.Dialog'
  85.     Include 'E16.Dialog'
  86.     INCLUDE 'M16.LineEdit'
  87.     INCLUDE 'M16.IntMath'
  88.     INCLUDE 'M16.Scrap'
  89.     INCLUDE 'M16.Desk'
  90.     InCLUDE 'M16.list'
  91.     PRINT POP
  92.     
  93. DPHandle    equ 0
  94. DPPointer    equ DPHandle+4
  95. DeRef    equ DPPointer+4
  96. LastTick    equ 10
  97. temp1    equ 12
  98. temp2    equ 14
  99. LinePt    equ 16
  100. ScreenTab    equ 20
  101. CustomMHandle    equ 24
  102. CustomMPtr    equ 28
  103.  
  104. MarkItem    equ 258
  105. testINum    equ 267
  106. AddMenuItem    equ 263
  107. DelMenuItem    equ 265
  108. AddAMenu    equ 264
  109. DelAMenu    equ 266
  110. CMenuNums    equ 273
  111.  
  112. ScreenMode    equ mode320
  113. ScreenWidth    equ 320
  114. ; menu record offsets
  115.  
  116. MRMenuFlag    equ $0A
  117. MRMenuTWidth    equ $0E
  118. MRMenuTPtr    equ $10
  119.  
  120.     EJECT
  121. *******************************************************************************
  122. *
  123. Menus    PROC
  124. *
  125. * Description:    Main code of the program. This routine calls all the other
  126. *    main program parts in order.
  127. *
  128. *
  129. * Inputs:    None
  130. *
  131. * Outputs:    None
  132. *
  133. * External Refs:
  134.     Import QuitParms
  135.     Import InitTools
  136.     Import InitApp
  137.     Import EventLoop
  138.     Import CloseTools
  139. *
  140. * Entry Points:
  141. *
  142. *******************************************************************************
  143.  
  144.     jsr InitTools
  145.     jsr InitApp
  146.  
  147.     _ShowCursor
  148.  
  149.     jsr EventLoop
  150.     jsr CloseTools
  151.  
  152.     _Quit QuitParms
  153.  
  154.     EndP
  155.  
  156.     EJECT
  157. *******************************************************************************
  158. *
  159. Globals    Record
  160. *
  161. * Description:    This area contains data used in all routines of the program
  162. *    it also contains some data structures used by Menus.Init
  163. *
  164. *
  165. * Inputs:    None
  166. *
  167. * Outputs:    None
  168. *
  169. * External Refs:
  170.     Export QuitParms
  171.     Import CustomMenu
  172. *
  173. * Entry Points:
  174. *
  175. *******************************************************************************
  176. *
  177. * standard global data here
  178. *
  179. *******************************************************************************
  180. TitleString    str 'Apple IIgs Menus Demo'
  181. AutString    str 'By Mensch / Copyright (c)'
  182. CRString    str '1988-1990 Apple Computer'
  183. VersString    str 'Version: 3.0'
  184.  
  185. MenuHeight    ds.b 2    ; Stored height of menu bar
  186. MyID    ds.b 2    ; application ID
  187. MyDP    ds.b 2    ; My zero page storage
  188.  
  189. QuitFlag    ds.w 1
  190. QuitParms    dc.l 0    ; Pathname of next app
  191.     dc.w $00    ; flags
  192. EventRecord
  193. EventWhat    ds.b 2
  194. EventMessage    ds.b 4
  195. EventWhen    ds.b 4
  196. EventWhere    ds.b 4
  197. EventModifiers    ds.b 2
  198. TaskData    ds.b 4
  199. TaskMask    dc.l $0000FFFF
  200.  
  201. *
  202. * Application specific data goes here
  203. *
  204.  
  205. AppMenu    dc.b '$$@\XN1',$0D
  206.     dc.b '--About Menus...\N256V',$0D
  207.     dc.b '.'
  208. FileMenu    dc.b '$$ File \N2',$0D
  209.     dc.b '--Quit\N257*Qq',$0D
  210.     dc.b '.'
  211. MenuMenu    dc.b '$$ Actions \N3',$0D
  212.     dc.b '--Mark Item\N258*Cc',$0D
  213.     dc.b '--Set Blinks\N259',$0D
  214.     dc.b '--Change Test Item Text\N260',$0D
  215.     dc.b '--Disable Test Item\N261',$0D
  216.     dc.b '--Enable Test Item\N262',$0D
  217.     dc.b '--Add a Menu Item\N263',$0D
  218.     dc.b '--Add a Menu\N264D',$0D
  219.     dc.b '--Delete a Menu Item\N265D',$0D
  220.     dc.b '--Delete a Menu\N266V',$0D
  221.     dc.b '--Test Item\N267',$0D
  222.     dc.b '.'
  223.  
  224. CMDTitle    dc.b '$$ Custom \N5',$0D,$00
  225.     dc.b '.'
  226.     
  227. TestMenu    dc.b '$$ Test \N4',$0D
  228.     dc.b '--Normal\N268',$0d
  229.     dc.b '--Bold\N269B',$0D
  230.     dc.b '--Disabled\N270D',$0d
  231.     dc.b '--Italics\N271I',$0d
  232.     dc.b '--Color Replace Highlight\N272X',$0d
  233.     dc.b '.'
  234.  
  235. Rect    ds.b 8
  236. MyRect    ds.b 8
  237.  
  238. TestMHandle    ds.b 4
  239.  
  240. CMDMenuProc    dc.l CustomMenu    ; custom menu proc
  241. PatTable    dc.l MyPattern1,MyPattern2,MyPattern3,MyPattern4
  242.  
  243. MyPattern1    dc.b $55,$55,$55,$55 ; patterns used by    the custom menu
  244.     dc.b $55,$55,$55,$55 ; when the user selects a color
  245.     dc.b $55,$55,$55,$55 ; these are the patterns that are
  246.     dc.b $55,$55,$55,$55 ; used to set the menu bar color
  247.     dc.b $55,$55,$55,$55
  248.     dc.b $55,$55,$55,$55
  249.     dc.b $55,$55,$55,$55
  250.     dc.b $55,$55,$55,$55
  251. MyPattern2    dc.b $77,$77,$77,$77
  252.     dc.b $77,$77,$77,$77
  253.     dc.b $77,$77,$77,$77
  254.     dc.b $77,$77,$77,$77
  255.     dc.b $77,$77,$77,$77
  256.     dc.b $77,$77,$77,$77
  257.     dc.b $77,$77,$77,$77
  258.     dc.b $77,$77,$77,$77
  259. MyPattern3    dc.b $44,$44,$44,$44
  260.     dc.b $44,$44,$44,$44
  261.     dc.b $44,$44,$44,$44
  262.     dc.b $44,$44,$44,$44
  263.     dc.b $44,$44,$44,$44
  264.     dc.b $44,$44,$44,$44
  265.     dc.b $44,$44,$44,$44
  266.     dc.b $44,$44,$44,$44
  267. MyPattern4    dc.b $22,$22,$22,$22
  268.     dc.b $22,$22,$22,$22
  269.     dc.b $22,$22,$22,$22
  270.     dc.b $22,$22,$22,$22
  271.     dc.b $22,$22,$22,$22
  272.     dc.b $22,$22,$22,$22
  273.     dc.b $22,$22,$22,$22
  274.     dc.b $22,$22,$22,$22
  275.     EndR
  276.  
  277.  
  278.     EJECT
  279. *******************************************************************************
  280. *
  281. CustomMenu    PROC
  282. *
  283. * Description:    This is the whole custom menu routine. This routine takes care
  284. *    of all drawing and selecting of the custom menu. It starts out 
  285. *    with a dispatch routine to dispatch the    operations the menu
  286. *    manager requests.
  287. *
  288. *
  289. * Inputs:    None
  290. *
  291. * Outputs:    None
  292. *
  293. * External Refs:    None
  294. *
  295. * Entry Points:    None
  296. *
  297. *******************************************************************************
  298.     with Globals
  299. local    equ 8    ; number of bytes of local stack frame
  300. Temp    equ $01
  301. mPtr    equ $04
  302. RetAddr    equ $01+local    ; stack frame constants
  303. MenuParam    equ $04+local
  304. yHitPt    equ $06+local
  305. xHitPt    equ $08+local
  306. rectPtr    equ $0A+local
  307. mHandle    equ $0E+local
  308. menuMessage    equ $12+local
  309. Result    equ $14+local
  310.  
  311. MaxItems    equ 5    ; number of menu items +1
  312. CMenuWidth    equ 50    ; menu is 50 x 50 pixels
  313. CMenuHeight    equ 50
  314.  
  315.     tdc    ; save the DPage
  316.     sta >tempDPage    ; to a temp value
  317.     tsc    ; get the stack pointer
  318.     sta >tempStack    ; and save it...
  319.  
  320.     sec
  321.     sbc #local    ; add in our temp data storage
  322.     tcs    ; set it as the stack pointer
  323.     tcd    ; and as the Dpage register
  324.  
  325.     phb    ; save the data bank register
  326.     phk    ; and switch to current bank
  327.     plb
  328.  
  329.     stz Result    ; zero out result ahead of time
  330.  
  331.     lda [mHandle]    ; dereference the menu handle
  332.     sta mPtr
  333.     ldy #2
  334.     lda [mHandle],y
  335.     sta mPtr+2
  336.  
  337.     lda menuMessage    ; now handle the message
  338.     asl a
  339.     tax
  340.     jmp (CMJumpTab,x)
  341.  
  342. CMenuDone
  343.     plb    ; restore the data bank register
  344.     lda >tempDPage    ; restore Dpage
  345.     tcd
  346.     lda >tempStack    ; restore stack pointer
  347.     tcs
  348.     ShortM    ; now discard parameter list
  349.     pla    ; save the return address in a and X
  350.     plx
  351.  
  352.     ply    ; discard all the parameters
  353.     ply
  354.     ply
  355.     ply
  356.     ply
  357.     ply
  358.     ply
  359.     ply
  360.  
  361.     phx    ; restore the return addres previously saved
  362.     pha
  363.     LongM
  364.  
  365.     rtl
  366.  
  367. *
  368. *   CMGetID -   accepts a menu internal    ID number and converts it into an
  369. *               application menu ID number. This is the number that is given
  370. *               to the application by taskmaster when you have completed
  371. *               your menu selection.
  372. *
  373.  
  374. CMGetID
  375.     lda MenuParam    ; get the internal item ID
  376.     clc    ; and add application offset to
  377.     adc #CMenuNums    ; create actual item number
  378.     sta Result    ; save the result
  379.     brl CMenuDone    ; and return back to dispatch routine
  380.  
  381. *
  382. *   CMDrawI -   Called when the menu manager wants to Hilight/unhilight a
  383. *               menu item in your menu ( when mouse is dragged onto or off
  384. *               of the item ) This routine calls either DrawItem or HilighItem
  385. *               depending on the request
  386. *
  387.  
  388. CMDrawI
  389.     lda MenuParam    ; get the number
  390.     bmi CMDIHiLite    ; if high bit set then highlite
  391.     jsr DrawItem    ; else just draw it
  392.     brl CMenuDone
  393. CMDIHiLite    and #$7FFF    ; strip the high bit
  394.     jsr InvertItem
  395.     brl CMenuDone
  396.  
  397. *
  398. *   CMDrawT -   The    menu manager asks for this call when it    is drawing the
  399. *               menu title. I want the menu manager to draw    my title
  400. *               so I just pass back a false result and the menu mgr handles
  401. *               it for me
  402.  
  403. CMDrawT
  404.     stz Result    ; false to have menu mgr do this...
  405.     brl CMenuDone
  406.  
  407. *
  408. *   CMSize -    Calculate values for menuWidth and menuHeight in the menu record
  409. *
  410.  
  411. CMSize
  412.     ldy #omenuWidth    ; offset into menu record
  413.     lda [mPtr],y    ; get the width parameter
  414.     bne CMS0010    ; if non-zero do not change the value            
  415.     lda #CMenuWidth    ; save # of pixels wide
  416.     sta [mPtr],y
  417. CMS0010    ldy #omenuHeight    ; offset into menu record for height
  418.     lda [mPtr],y    ; load the height
  419.     bne CMS0020    ; if non-zero do not change them
  420.     lda #CMenuHeight
  421.     sta [mPtr],y
  422. CMS0020
  423.     brl CMenuDone
  424.  
  425. *
  426. *   CMChoose -  Routine called when user mouse location changes. This routine
  427. *               should return  in the result the internal ID number of the
  428. *               item the mouse point is    currently over. If no item selected
  429. *               leave the result alone.
  430. *
  431.  
  432. CMChoose
  433.     lda #1    ; initialize the counter at 1
  434.     sta itemTemp    ; This will count thru each menu item to test
  435. CMC0010
  436.     lda itemTemp    ; get the item number to test
  437.     cmp #MaxItems    ; are we done yet???
  438.     bge CMCDone    ; if so then quit...
  439.     jsr TestHit    ; test each item for a hit
  440.     bne CMCHit    ; if non-zero got a    hit
  441.     inc itemTemp    ; bump the counter
  442.     bra CMC0010    ; and try the next item
  443. CMCHit    lda itemTemp    ; got a hit so return the number
  444.     ora #$8000    ; set high order bit to flag as selected
  445.     sta Result    ; and save it as the result
  446. CMCDone
  447.     brl CMenuDone    ; and leave
  448.  
  449. *
  450. *   CMDraw -    This routine draws the contents of the custom menu when the
  451. *               menu is first selected.
  452. *
  453.  
  454. CMDraw
  455.  
  456.     lda #1    ; draw item 1
  457.     jsr DrawItem
  458.  
  459.     lda #2
  460.     jsr DrawItem
  461.  
  462.     lda #3
  463.     jsr DrawItem
  464.  
  465.     lda #4
  466.     jsr DrawItem
  467.  
  468.     brl CMenuDone
  469.  
  470. *
  471. * SetUpRect - sets tempRect equal to the rectangle of the custom menu item
  472. * in <A>. This routine is used by drawItem,InvertItem and TestHit
  473. *
  474.  
  475. SetUpRect
  476.     dec a    ; item numbers based off of 1 not 0
  477.     asl a    ; item number *8 for offset into rect table
  478.     asl a
  479.     asl a
  480.     tax    ; place it in x to use as an index
  481.  
  482.     ldy #2    ; get values to offset rectangle by
  483.     lda [rectPtr],y    ; wmgr rectangle left
  484.     sta tempPt+2    ; and save it for use later
  485.     lda [rectPtr]    ; now get the top
  486.     sta tempPt
  487.  
  488.     lda MyRect1,x    ; load in the top
  489.     clc    ; and add the offset
  490.     adc tempPt
  491.     sta tempRect    ; and store it 
  492.  
  493.     lda MyRect1+2,x    ; load in the left
  494.     clc
  495.     adc tempPt+2    ; offset it
  496.     sta tempRect+2
  497.  
  498.     lda MyRect1+4,x    ; Load the bottom
  499.     clc
  500.     adc tempPt
  501.     sta tempRect+4
  502.  
  503.     lda MyRect1+6,x    ; and finally the right
  504.     clc
  505.     adc tempPt+2
  506.     sta tempRect+6
  507.  
  508.     rts
  509.  
  510. *
  511. *   DrawItem -  Draw the menu item contained in A
  512. *
  513.  
  514. DrawItem        ; draws item specified by a
  515.     sta itemTemp
  516.     jsr SetUpRect
  517.  
  518.     PushLong #tempRect
  519.     lda PatTable+2    ; get high word of pattern addr
  520.     pha
  521.     lda itemTemp    ; push pattern ptr low byte
  522.     dec a    ; item# based from 1 not 0
  523.     asl a    ; multiply by 4 and    use it as a
  524.     asl a    ; table offset
  525.     tax
  526.     lda PatTable,x
  527.     pha
  528.     _FillRect
  529.     rts
  530.  
  531. *
  532. *   InvertItem -    Invert an Item to show it is selected
  533. *
  534.  
  535. InvertItem
  536.     jsr SetUpRect
  537.  
  538.     PushLong #tempRect
  539.     _InvertRect
  540.     rts
  541.  
  542. *
  543. *   TestHit -   With an Item number passed in A test to see    if 
  544. *               the    cursor is over the Item. If so return true, if not return false
  545. *
  546.  
  547. TestHit
  548.     jsr SetUpRect    ; create rectangle to test
  549.  
  550.     lda yHitPt    ; create a point from the passed data
  551.     sta tempPt    ; since we must pass this data by pointer
  552.     lda xHitPt    ; to PtInRect, we must move the data from
  553.     sta tempPt+2    ; the stack frame into temp storage
  554.  
  555.     PushWord #0    ; room for result
  556.     PushLong #tempPt    ; current cursor location
  557.     PushLong #tempRect    ; item rectangle to    test
  558.     _PtInRect
  559.     pla    ; return result in A
  560.  
  561.     rts
  562.  
  563. *
  564. *   Data storage area for the custom menu routine
  565. *
  566.  
  567. tempStack    ds.b 2    ; storage for Stack    and Dpage registers
  568. tempDPage    ds.b 2
  569. CMJumpTab        ; jump table for the dispatch routine
  570.     dc.w CMDraw    ; mDrawMenu routine
  571.     dc.w CMChoose    ; mChoose routine
  572.     dc.w CMSize    ; mSize routine
  573.     dc.w CMDrawT    ; mDrawTitle routine
  574.     dc.w CMDrawI    ; mDrawMItem Routine
  575.     dc.w CMGetID    ; mGetMItemID routine
  576.  
  577. MyRect1    dc.w 3,3,23,23    ; rectangles for the 4 menu items
  578. MyRect2    dc.w 25,3,45,23
  579. MyRect3    dc.w 3,25,23,45
  580. MyRect4    dc.w 25,25,45,45
  581. tempRect    ds.b 8    ; temp rectangle to    use in various places
  582. tempPt    ds.b 4    ; temp point to use    in various places
  583. itemTemp    ds.b 2
  584.  
  585.     endP
  586.  
  587.     EJECT
  588. *******************************************************************************
  589. *
  590. InitApp    PROC
  591. *
  592. * Description:    Initialize my menu bar and the quit flags. This demonstrates how
  593. *                   to install a custom menu!
  594. *
  595. *
  596. * Inputs:    None
  597. *
  598. * Outputs:    None
  599. *
  600. * External Refs:
  601.     import ColorSel
  602. * Entry Points:
  603. *
  604. *******************************************************************************
  605.     With Globals
  606.  
  607.     Stz QuitFlag    ; initialize the quit flag
  608.  
  609.  
  610.     PushLong #0    ; room for result
  611.     PushLong #CMDTitle    ; our custom menu
  612.     _NewMenu    ; now create a new menu
  613.  
  614.     lda 1,s    ; get menu pointer for later use
  615.     sta CustomMHandle    ; while leaving them on the stack   
  616.     lda 3,s
  617.     sta CustomMHandle+2
  618.  
  619.     lda [CustomMHandle]    ; dereference the menu handle 
  620.     sta CustomMPtr
  621.     ldy #2
  622.     lda [CustomMHandle],y
  623.     sta CustomMPtr+2
  624.  
  625.     lda CMDMenuProc    ; now fix it so that this is a cust menu
  626.     ldy #omenuProc    ; by setting the menu proc to point to 
  627.     sta [CustomMPtr],y    ; our custom procedure
  628.     lda CMDMenuProc+2
  629.     iny
  630.     iny
  631.     sta [CustomMPtr],y
  632.  
  633.     ldy #omenuFlag
  634.     lda [CustomMPtr],y
  635.     ora #menuCustom
  636.     sta [CustomMPtr],y
  637.  
  638.  
  639. ; Set up custom menu info here ....
  640.  
  641.     PushWord #0    ; menu handle already on stack insert 
  642.     _InsertMenu    ; it before all other menus
  643.  
  644.     PushLong #0
  645.     PushLong #TestMenu
  646.     _NewMenu
  647.  
  648.     lda 1,s    ; get menu pointer for later use
  649.     sta TestMHandle    ; and leave it on the stack
  650.     lda 3,s
  651.     sta TestMHandle+2
  652.  
  653.     PushWord #0
  654.     _InsertMenu
  655.  
  656.     PushLong #0
  657.     PushLong #MenuMenu
  658.     _NewMenu
  659.     PushWord #0
  660.     _InsertMenu
  661.  
  662.     PushLong #0
  663.     PushLong #FileMenu
  664.     _NewMenu
  665.     PushWord #0
  666.     _InsertMenu
  667.  
  668.     PushLong #0
  669.     PushLong #AppMenu
  670.     _NewMenu
  671.     PushWord #0
  672.     _InsertMenu
  673.  
  674.     PushWord #1    ; Add NDA's
  675.     _FixAppleMenu
  676.  
  677.     PushWord #0
  678.     _FixMenuBar
  679.     Pla
  680.     sta MenuHeight
  681.  
  682.     PushWord #$00F5    ; white-blue/red not selected colors
  683.     PushWord #$0010    ; blue/red-black selected colors
  684.     PushWord #$00E0    ; yellowgreen outline
  685.     _SetBarColors    ; now set the bar colors
  686.  
  687.     lda #274    ; Get the inverse color the the Apple
  688.     sta TaskData    ; Menu set up correctly.
  689.     jsr ColorSel
  690.  
  691.     rts
  692.     EndP
  693.  
  694.     EJECT
  695. *******************************************************************************
  696. *
  697. EventLoop    PROC
  698. *
  699. * Description:    The event loop recieves events and dispatches them. When
  700. *    the quitflag is non-zero, it exits.
  701. *
  702. * Inputs:    None
  703. *
  704. * Outputs:    None
  705. *
  706. * External Refs:
  707.     Import MenuSelect
  708.     Import Ignore
  709. *
  710. * Entry Points:
  711. *
  712. *******************************************************************************
  713.     With Globals
  714.  
  715.     PushWord #0    ; room for result
  716.     PushWord #everyEvent ; handle all events
  717.     PushLong #EventRecord ; place event data here
  718.     _TaskMaster
  719.  
  720.     pla    ; get the event type here
  721.     beq EventLoop    ; remove if you want to use null events
  722.     asl A    ; multiply by two
  723.     tax    ; and do a table dispatch just like menu select
  724.     jsr (TaskTable,x)
  725.  
  726.     lda QuitFlag    ; test to see if user selected quit
  727.     beq EventLoop    ; if not just go get another event
  728.  
  729.     rts    ; if so, then end the event loop
  730.  
  731. TaskTable    dc.w Ignore    ; 0 Null
  732.     dc.w Ignore    ; 1 MouseDown
  733.     dc.w Ignore    ; 2 Mouse Up
  734.     dc.w Ignore    ; 3 KeyDown
  735.     dc.w Ignore    ; 4 Undefined
  736.     dc.w Ignore    ; 5 AutoKey
  737.     dc.w Ignore    ; 6 Update
  738.     dc.w Ignore    ; 7 undefined
  739.     dc.w Ignore    ; 8 activate
  740.     dc.w Ignore    ; 9 Switch
  741.     dc.w Ignore    ; 10 desk acc
  742.     dc.w Ignore    ; 11 device driver
  743.     dc.w Ignore    ; 12 ap
  744.     dc.w Ignore    ; 13 ap
  745.     dc.w Ignore    ; 14 ap
  746.     dc.w Ignore    ; 15 ap
  747.     dc.w Ignore    ; TASK 0 indesk
  748.     dc.w MenuSelect    ; TASK 1 in menuBar
  749.     dc.w Ignore    ; TASK 2 in system window
  750.     dc.w Ignore    ; TASK 3 in content
  751.     dc.w Ignore    ; TASK 4 in Drag
  752.     dc.w Ignore    ; TASK 5 in grow
  753.     dc.w Ignore    ; TASK 6 in goaway
  754.     dc.w Ignore    ; TASK 7 in zoom
  755.     dc.w Ignore    ; TASK 8 in info bar
  756.     dc.w Ignore    ; TASK 9 in special    menu
  757.     dc.w Ignore    ; TASK 10 in NDA
  758.     dc.w Ignore    ; TASK 11 in frame
  759.     dc.w Ignore    ; TASK 12 in drop
  760.     EndP
  761.  
  762.     EJECT
  763. *******************************************************************************
  764. *
  765. MenuSelect    PROC
  766. *
  767. * Description:    This routine is called when taskmaster returns 
  768. *    a menu event. This routine takes the menu item that
  769. *    was hit and calculates an offset into the menu
  770. *    dispatch table. It then calls that routine
  771. *
  772. *
  773. * Inputs:    None
  774. *
  775. * Outputs:    None
  776. *
  777. * External Refs:
  778.     Import DoAbout
  779.     Import DoQuit
  780.     Import SetMark
  781.     Import SetBlink
  782.     Import SetName
  783.     Import DisableIt
  784.     Import EnableIt
  785.     Import DoAdd
  786.     Import DoAddM
  787.     Import DoRemove
  788.     Import DoRemoveM
  789.     Import ColorSel
  790.     Import Ignore
  791. *
  792. * Entry Points:
  793. *
  794. *******************************************************************************
  795.     With Globals
  796.  
  797.     lda TaskData    ; get the menu number hit
  798.     sec    ; subtract 250 ( that is where our menu    numbers
  799.     sbc #256    ; start)
  800.     asl a    ; multiply it by 2 ( table has 2 byte entries )
  801.     tax    ; use as an index
  802.     jsr (menuTable,x)    ; and jump to the routine to handle that item
  803.  
  804.     PushWord #0    ; unhilight the menu bar now
  805.     PushWord TaskData+2    ; menu number that was hit
  806.     _HiLiteMenu
  807.  
  808.     rts
  809. ;
  810. ; the menu table should contain one entry for each menu item
  811. ;
  812. menuTable    dc.w DoAbout    ; 256 About Menus
  813.     dc.w DoQuit    ; 257 Quit
  814.     dc.w SetMark    ; 258 Mark test item
  815.     dc.w SetBlink    ; 259 Set Blink rate
  816.     dc.w SetName    ; 260 Change test item text
  817.     dc.w DisableIt    ; 261 Disable test item
  818.     dc.w EnableIt    ; 262 enable test item
  819.     dc.w DoAdd    ; 263 add menu item
  820.     dc.w DoAddM    ; 264 add menu
  821.     dc.w DoRemove    ; 265 delete menu item
  822.     dc.w DoRemoveM    ; 266 delete menu
  823.     dc.w Ignore    ; 267 test item
  824.     dc.w Ignore    ; 268 normal
  825.     dc.w Ignore    ; 269 bold
  826.     dc.w Ignore    ; 270 disabled
  827.     dc.w Ignore    ; 271 italics
  828.     dc.w Ignore    ; 272 color replace
  829.     dc.w Ignore    ; 273 Not implemented
  830.     dc.w ColorSel    ; 274 color selection
  831.     dc.w ColorSel    ; 275 color selection
  832.     dc.w ColorSel    ; 276 color selection
  833.     dc.w ColorSel    ; 277 Color selection
  834.  
  835.     EndP
  836.  
  837.     EJECT
  838. *******************************************************************************
  839. *
  840. SetMark    PROC
  841. *
  842. * Description:    Demonstrate how to Mark/UnMark an item.
  843. *
  844. *
  845. * Inputs:    None
  846. *
  847. * Outputs:    None
  848. *
  849. * External Refs:
  850. *
  851. * Entry Points:
  852. *
  853. *******************************************************************************
  854.  
  855.     PushWord #0    ; room for result
  856.     PushWord #MarkItem    ; test menu item number
  857.     _GetMItemMark
  858.  
  859.     pla    ; get current mark status
  860.     bne SMUnMark    ; if not zero then unmark it
  861.  
  862.     PushWord #18    ; else mark with ascii 18
  863.     PushWord #MarkItem
  864.     _SetMItemMark
  865.     rts
  866.  
  867. SMUnMark
  868.     PushWord #0    ; Unmark the test item
  869.     PushWord #MarkItem
  870.     _SetMItemMark
  871.     rts
  872.     EndP
  873.  
  874.     EJECT
  875. *******************************************************************************
  876. *
  877. EnableIt    PROC
  878. *
  879. * Description:    Demonstrate how to enable a menu item
  880. *
  881. *
  882. * Inputs:    None
  883. *
  884. * Outputs:    None
  885. *
  886. * External Refs:    None
  887. *
  888. * Entry Points:
  889. *
  890. *******************************************************************************
  891.  
  892.     PushWord #testINum
  893.     _EnableMItem
  894.     rts
  895.     EndP
  896.  
  897.  
  898. *******************************************************************************
  899. *
  900. DisableIt    PROC
  901. *
  902. * Description:    Demonstrate how to disable a menu item
  903. *
  904. *
  905. * Inputs:    None
  906. *
  907. * Outputs:    None
  908. *
  909. * External Refs:    None
  910. *
  911. * Entry Points:    None
  912. *
  913. *******************************************************************************
  914.     PushWord #testINum
  915.     _DisableMItem
  916.     rts
  917.     EndP
  918.  
  919.     EJECT
  920. *******************************************************************************
  921. *
  922. SetName    PROC
  923. *
  924. * Description:    Change the name of the test item. This routine will
  925. *    toggle between the names 'Test Item' and 'Improved Test Item'
  926. *    to show how to change an Item name.
  927. *
  928. * Inputs:    None
  929. *
  930. * Outputs:    None
  931. *
  932. * External Refs:
  933. *
  934. * Entry Points:
  935. *
  936. *******************************************************************************
  937.     lda NameFlag    ; test state of current name if non then
  938.     beq SN0010    ; name still original/ needs changing
  939.  
  940.     stz NameFlag    ; zero name flag to    denote alt name
  941.     PushLong #NewName    ; Set the new name
  942.     PushWord #testINum
  943.     _SetMItemName
  944.     rts
  945. SN0010
  946.     lda #1    ; set flag to denote original item displayed
  947.     sta NameFlag
  948.     PushLong #OrigName
  949.     PushWord #testINum
  950.     _SetMItemName
  951.     rts
  952. NewName    str 'Improved test item'
  953. OrigName    str 'Test Item'
  954. NameFlag    dc.w 1
  955.     EndP
  956.  
  957.     EJECT
  958. *******************************************************************************
  959. *
  960. SetBlink    PROC
  961. *
  962. * Description:    Changes the number of times selected menu items blink.
  963. *
  964. *
  965. * Inputs:    None
  966. *
  967. * Outputs:    None
  968. *
  969. * External Refs:
  970. *
  971. * Entry Points:
  972. *
  973. *******************************************************************************
  974.     PushWord BRate
  975.     _SetMItemBlink
  976.  
  977.     lda BRate
  978.     eor #$0003    ; xor with 3 to swap between 1 and 2
  979.     sta BRate
  980.  
  981.     rts
  982. BRate    dc.w 1    ; the next blink rate
  983.     EndP
  984.  
  985.     EJECT
  986. *******************************************************************************
  987. *
  988. ColorSel    PROC
  989. *
  990. * Description:    This routine will be called when the user selects one of 
  991. *    the custom menu items. It will change the menu bar color
  992. *    to the color selected by the user.
  993. *
  994. *
  995. * Inputs:    TaskData - Menu item selected
  996. *
  997. * Outputs:    None
  998. *
  999. * External Refs:    None
  1000. *
  1001. * Entry Points:    None
  1002. *
  1003. *******************************************************************************
  1004.     With Globals
  1005.  
  1006.     lda TaskData    ; get the menu number
  1007.     sec    ; and make it a number between 0 and 3
  1008.     sbc #CMenuNums+1    ; by subtracting the selection offset
  1009.     asl a    ; multiply by 4 to use as a table offset
  1010.     asl a
  1011.     tax
  1012.     lda PatTable,x    ; get address of pattern
  1013.     sta DeRef    ; and use it as a pointer
  1014.     lda (DeRef)    ; get the selected color
  1015.     and #$000F    ; strip off high bytes
  1016.     ora #$00F0    ; set nibble to white
  1017.     pha    ; set menu colors to white/selected color
  1018.  
  1019.     PushWord #$0040    ; blue/black selected colors
  1020.     PushWord #$0020    ; brown outline
  1021.     _SetBarColors
  1022.  
  1023.     _DrawMenuBar
  1024.  
  1025.     rts
  1026.     EndP
  1027.     
  1028.     EJECT
  1029. *******************************************************************************
  1030. *
  1031. Ignore    PROC
  1032. *
  1033. * Description:    This routine is called for all events and menu selection
  1034. *    that are not handled by this program. Like the name says
  1035. *    it ignores them.
  1036. *
  1037. *
  1038. * Inputs:    None
  1039. *
  1040. * Outputs:    None
  1041. *
  1042. * External Refs:
  1043. *
  1044. * Entry Points:
  1045. *
  1046. *******************************************************************************
  1047.     rts
  1048.     EndP
  1049.  
  1050.  
  1051. *******************************************************************************
  1052. *
  1053. DoQuit    PROC
  1054. *
  1055. * Description:    This routine stores a non-zero value in the quit flag to
  1056. *    notify the event loop that the user wants to stop the
  1057. *    program.
  1058. *
  1059. *
  1060. * Inputs:    None
  1061. *
  1062. * Outputs:    None
  1063. *
  1064. * External Refs:
  1065. *
  1066. * Entry Points:
  1067. *
  1068. *******************************************************************************
  1069.     With Globals
  1070.  
  1071.     lda #1
  1072.     sta QuitFlag
  1073.     rts
  1074.     EndP
  1075.  
  1076.     EJECT
  1077. *******************************************************************************
  1078. *
  1079. DoAdd    PROC
  1080. *
  1081. * Description:    Demonstrates hot to Add an Item to an existing menu. 
  1082. *    After adding the item this routine disables 
  1083. *    the Add item and enable the delete item.
  1084. *
  1085. *
  1086. * Inputs:    None
  1087. *
  1088. * Outputs:    None
  1089. *
  1090. * External Refs:
  1091. *
  1092. * Entry Points:
  1093. *
  1094. *******************************************************************************
  1095.     With Globals
  1096.  
  1097.     PushLong #NewItem    ; Pointer to the new Item
  1098.     PushWord #$FFFF    ; Insert at end of the menu
  1099.     PushWord #$03    ; insert into menu 3
  1100.     _InsertMItem
  1101.  
  1102.     PushWord #0    ; Call calc Menusize to get menu mgr to
  1103.     PushWord #0    ; recalc the menu size. 
  1104.     PushWord #3    ; Use zeros for auto calculation
  1105.     _CalcMenuSize
  1106.  
  1107.     PushWord #AddMenuItem ; Now disable the    Add item 
  1108.     _DisableMItem
  1109.  
  1110.     PushWord #DelMenuItem ; and enable the delete item so the 
  1111.     _EnableMItem    ; user can get rid of item just added
  1112.  
  1113.     rts
  1114. NewItem    dc.b '--New Item\N318D',$0D 
  1115.     EndP
  1116.  
  1117.     EJECT
  1118. *******************************************************************************
  1119. *
  1120. DoRemove    PROC
  1121. *
  1122. * Description:    Demonstrate how to remove an item. The menu item
  1123. *    for this routine is enabled only after AddItem adds
  1124. *    an item. This routine disables the delete item and
  1125. *    re-enables the add item
  1126. *
  1127. *
  1128. * Inputs:    None
  1129. *
  1130. * Outputs:    None
  1131. *
  1132. * External Refs:
  1133. *
  1134. * Entry Points:
  1135. *
  1136. *******************************************************************************
  1137.     With Globals
  1138.  
  1139.     PushWord #318    ; item ID of added item
  1140.     _DeleteMItem
  1141.  
  1142.     PushWord #0    ; recalc menu size with automatic 
  1143.     PushWord #0    ; calculation by passing 0's
  1144.     PushWord #3    ; recalc menu 0
  1145.     _CalcMenuSize
  1146.  
  1147.     PushWord #DelMenuItem ; disable this cause now, theres 
  1148.     _DisableMItem    ; nothing to remove
  1149.  
  1150.     PushWord #AddMenuItem ; enable this again, so the user 
  1151.     _EnableMItem    ; can try again
  1152.  
  1153.     rts
  1154.     EndP
  1155.  
  1156.     EJECT
  1157. *******************************************************************************
  1158. *
  1159. DoRemoveM    PROC
  1160. *
  1161. * Description:    Demonstrate how to remove an entire menu from the menu bar
  1162. *
  1163. *
  1164. * Inputs:    None
  1165. *
  1166. * Outputs:    None
  1167. *
  1168. * External Refs:
  1169. *
  1170. * Entry Points:
  1171. *
  1172. *******************************************************************************
  1173.     With Globals
  1174.  
  1175.     PushWord #4    ; menu number to remove
  1176.     _DeleteMenu
  1177.  
  1178.     _DrawMenuBar    ; redraw the menu bar
  1179.  
  1180.     PushWord #DelAMenu    ; disable this feature and enable Addmenu
  1181.     _DisableMItem
  1182.  
  1183.     PushWord #AddAMenu
  1184.     _EnableMItem
  1185.  
  1186.     rts
  1187.     EndP
  1188.  
  1189.     EJECT
  1190. *******************************************************************************
  1191. *
  1192. DoAddM    PROC
  1193. *
  1194. * Description:    Demonstrate how to add a menu to the menu bar.
  1195. *
  1196. *
  1197. * Inputs:    None
  1198. *
  1199. * Outputs:    None
  1200. *
  1201. * External Refs:
  1202. *
  1203. * Entry Points:
  1204. *
  1205. *******************************************************************************
  1206.     With Globals
  1207.  
  1208.     PushLong TestMHandle ; handle to the test menu we saved in InitApp
  1209.     PushWord #3    ; insert after menu    3
  1210.     _InsertMenu
  1211.  
  1212.     _DrawMenuBar    ; redraw the menu bar
  1213.  
  1214.     PushWord #AddAMenu    ; and disable this menu option
  1215.     _DisableMItem
  1216.  
  1217.     PushWord #DelAMenu    ; enable the option    to delete this menu
  1218.     _EnableMItem
  1219.  
  1220.     rts
  1221.     EndP
  1222.     
  1223.     Include 'Menus.inits.aii'
  1224.  
  1225.     END
  1226.  
  1227.